package vip.liux.contracts.models.coupon;

import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
import vip.liux.contracts.shared.enums.Status;
import vip.liux.contracts.shared.enums.coupon.CouponType;
import vip.liux.contracts.shared.enums.coupon.UseScope;
import vip.liux.contracts.shared.enums.coupon.UseType;
import vip.liux.domain.entities.auditing.CreationAuditedEntity;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;


@Getter
@Setter
@Entity
@Table(name = "shop_coupon")
public class Coupon extends CreationAuditedEntity<Long> {

    /**
     * 消费商品编号
     */
    @Column(name = "coupon_no", length = 50)
    private String couponNo;

    /**
     * 优惠券名称
     */
    @Column(name = "coupon_name", length = 256)
    private String couponName;

    /**
     * 优惠券类型 0立减券 1折扣券
     */
    @Enumerated(EnumType.ORDINAL)
    @Column(name = "coupon_type", nullable = false)
    private CouponType couponType;

    /**
     * 优惠金额
     */
    @Column(name = "amount", precision = 6, scale = 2)
    private BigDecimal amount;

    /**
     * 折扣券-折扣率(0-1.00)
     */
    @Column(name = "discount", nullable = false, precision = 3, scale = 2)
    private BigDecimal discount;

    /**
     * 使用门槛(0无门槛 1满金额可用)
     */
    @Enumerated(EnumType.ORDINAL)
    @Column(name = "use_type")
    private UseType useType;

    /**
     * 满减条件
     */
    @Column(name = "full", nullable = false, precision = 10, scale = 2)
    private BigDecimal full;

    /**
     * 优惠券描述
     */
    @Column(name = "`describe`", nullable = false, length = 500)
    private String describe;

    /**
     * 领取开始时间
     */
    @Column(name = "receive_start", nullable = false)
    private LocalDateTime receiveStart;

    /**
     * 领取截止时间
     */
    @Column(name = "receive_end", nullable = false)
    private LocalDateTime receiveEnd;

    /**
     * 使用开始时间
     */
    @Column(name = "use_start", nullable = false)
    private LocalDateTime useStart;

    /**
     * 使用截止时间
     */
    @Column(name = "use_end", nullable = false)
    private LocalDateTime useEnd;

    /**
     * 总数
     */
    @Column(name = "receive_num")
    private Long receiveNum;

    /**
     * 每人可领取张数
     */
    @Column(name = "receive_num_limit")
    private Long receiveNumLimit;

    /**
     * 使用范围，0全品，1部分商品
     */
    @Enumerated(EnumType.ORDINAL)
    @Column(name = "use_scope", nullable = false)
    private UseScope useScope;

    /**
     * 暂定为商品ID集合，后续可能会有分类id集合
     */
    @Column(name = "scope_config")
    private Map<String, Object> scopeConfig;

    /**
     * 排序方式(数字越小越靠前)
     */
    @Column(name = "sort", nullable = false)
    private Integer sort;

    /**
     * 状态(0正常 1停止)
     */
    @Enumerated(EnumType.ORDINAL)
    @Column(name = "status", nullable = false)
    private Status status;

    @OneToMany(mappedBy = "coupon")
    private Set<UserCoupon> userCoupons = new LinkedHashSet<>();

    public void setId(Long id) {
        super.setId(id);
    }
}